////////////////////////////////////////////////////////////////////////////////
// Copyright 2006 CORE Solutions Limited
// All rights reserved.
// PROPRIETARY AND CONFIDENTIAL INFORMATION.
// Use is subject to license terms.
//
// FUNCTION ID      :   USER
// AUTHOR           :   Victor Zheng 
// DATE CREATE      :   2006/02/01
// DESCRIPTION      :   a MAINTENANCE ACTION file for the function, USER
//                  :   
//                  :   
//                  :   
//
// MODIFICATION HISTORY:
// DATE         AUTHOR          VERSION NO.         COMMENT
// -----------  --------------  ------------------  -------------------
// 2006/02/01   Victor Zheng    1.0                 source is generated.
// 2006/06/20   William Xu      1.0                 BugZilla #6277
// 2006/08/28   Jimmy Chen      1.7                 Status should default to ACTIVE
//
////////////////////////////////////////////////////////////////////////////////

package com.erp.app.admin.userSetup.web;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

import com.erp.app.admin.userSetup.pk.UserPk;
import com.erp.app.admin.userSetup.schema.UserSchema;
import com.erp.app.admin.userSetup.vo.UserVo;
import com.erp.app.common.ProjectConstants;
import com.erp.app.util.web.WebUtil;
import com.erp.common.web.SearchResultRow;
import com.erp.framework.controller.action.SimpleMaintStyleActionTemplate;
import com.erp.framework.model.pk.SimpleBasePk;
import com.erp.framework.model.schema.TableSchema;
import com.erp.framework.util.CommonUtil;
import com.erp.framework.util.logger.Logger;
import com.erp.framework.util.user.User;

/**
* A <strong>Maintenance Action</strong> is an adapter between the contents of an incoming
* HTTP request and the corresponding business logic that should be executed to
* process this request.  The controller (ActionServlet) will select an
* appropriate Action for each request.
* The main purpose for this action class is to handle the user document maintenance events
* from the web browsers.
*
* @author          Victor Zheng 
* @version 1.0     2006/02/01
* @since           FrameWork 1.0
*
*/
public class UserMaintenanceAction extends SimpleMaintStyleActionTemplate {

	////////////////////////////////////////////////////////////////////////////////
	// CONSTANTS DEFINITION
	////////////////////////////////////////////////////////////////////////////////

	//public static final String ACTION_DO_SOMETHING = "actionDoSomething";
	//public static final String STATUS_DO_SOMETHING = "statusDoSomething";

	
	public static final int TAB_IDX_HDR = -1;
	public static final int TAB_IDX_GMM = 0;
	public static final int TAB_IDX_SIGNATURE = 1;
	public static final int TAB_IDX_ACCESS_TEAM = 2;
	public static final int TAB_IDX_BUYER = 3;
	public static final int TAB_IDX_BRAND = 4;
	public static final int TAB_IDX_NT_TEAM = 5;
	
	
	public static final String HDR = "HDR";
	public static final String GMM = "Gmm";
	public static final String SIGNATURE = "Signature";
	public static final String ACCESS_TEAM = "AccessTeam";
	public static final String BUYER = "Buyer";
	public static final String BRAND = "Brand";
	public static final String NT_TEAM = "NTTeam";
	

	public static final String ACTION_CHANGE_FOLDER_HDR = ACTION_CHANGE_FOLDER + HDR;
	public static final String ACTION_CHANGE_FOLDER_GMM = ACTION_CHANGE_FOLDER + GMM;
	public static final String ACTION_CHANGE_FOLDER_SIGNATURE = ACTION_CHANGE_FOLDER + SIGNATURE;
	public static final String ACTION_CHANGE_FOLDER_ACCESS_TEAM = ACTION_CHANGE_FOLDER + ACCESS_TEAM;
	public static final String ACTION_CHANGE_FOLDER_BUYER = ACTION_CHANGE_FOLDER + BUYER;
	public static final String ACTION_CHANGE_FOLDER_BRAND = ACTION_CHANGE_FOLDER + BRAND;
	public static final String ACTION_CHANGE_FOLDER_NT_TEAM = ACTION_CHANGE_FOLDER + NT_TEAM;

	public static final String ACTION_ADD_GMM = ACTION_ADD_ROW + GMM;
	public static final String ACTION_ADD_SIGNATURE = ACTION_ADD_ROW + SIGNATURE;
	public static final String ACTION_ADD_ACCESS_TEAM = ACTION_ADD_ROW + ACCESS_TEAM;
	public static final String STATUS_ADD_ACCESS_TEAM = ACTION_ADD_ACCESS_TEAM;
	public static final String ACTION_ADD_BUYER = ACTION_ADD_ROW + BUYER;
	public static final String STATUS_ADD_BUYER = ACTION_ADD_BUYER;
	public static final String ACTION_ADD_BRAND = ACTION_ADD_ROW + BRAND;
	public static final String STATUS_ADD_BRAND = ACTION_ADD_BRAND;
	public static final String ACTION_ADD_NT_TEAM = ACTION_ADD_ROW + NT_TEAM;
	public static final String STATUS_ADD_NT_TEAM = ACTION_ADD_NT_TEAM;

	public static final String ACTION_DEL_GMM = ACTION_DELETE_ROW + GMM;
	public static final String ACTION_DEL_SIGNATURE = ACTION_DELETE_ROW + SIGNATURE;
	public static final String ACTION_DEL_ACCESS_TEAM = ACTION_DELETE_ROW + ACCESS_TEAM;
	public static final String ACTION_DEL_BUYER = ACTION_DELETE_ROW + BUYER;
	public static final String ACTION_DEL_BRAND = ACTION_DELETE_ROW + BRAND;
	public static final String ACTION_DEL_NT_TEAM = ACTION_DELETE_ROW + NT_TEAM;

	public static final String ACTION_ADD_SIGNATURE_ATTACH = "addSignatureAttach";
	public static final String STATUS_ADD_SIGNATURE_ATTACH = "addSignatureAttach_set";
	
	public static final String ACTION_VIEW_SIGNATURE_ATTACH = "viewSignatureAttach";

	public static final String ACTION_DEL_SIGNATURE_ATTACH = "delSignatureAttach";

	
	
	////////////////////////////////////////////////////////////////////////////////
	// GLOBAL VARIABLES DEFINITION
	////////////////////////////////////////////////////////////////////////////////



	////////////////////////////////////////////////////////////////////////////////
	// LOGICAL AND BUSINESS METHODS
	////////////////////////////////////////////////////////////////////////////////

 	public ActionForward handlePageEvent(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {
			if (!isHandled(request) && action.equalsIgnoreCase(ACTION_ADD_ATTACH)) {
	            setHandled(request);
	            actionForward = processActionAddAttach(mapping, form, request, response, errors);
	        }
			if (!isHandled(request) && action.equalsIgnoreCase(ACTION_VIEW_ATTACH)) {
	            setHandled(request);
	            actionForward = processActionViewAttach(mapping, form, request, response, errors);
	        }
	        if (!isHandled(request) && action.equalsIgnoreCase(ACTION_DEL_ATTACH)) {
	            setHandled(request);
	            actionForward = processActionDelAttach(mapping, form, request, response, errors);
	        }

			if (!isHandled(request) && action.equalsIgnoreCase(ACTION_ADD_SIGNATURE_ATTACH)) {
	            setHandled(request);
	            actionForward = processActionAddSignatureAttach(mapping, form, request, response, errors);
	        }
			if (!isHandled(request) && action.equalsIgnoreCase(ACTION_VIEW_SIGNATURE_ATTACH)) {
	            setHandled(request);
	            actionForward = processActionViewSignatureAttach(mapping, form, request, response, errors);
	        }

	        if (!isHandled(request) && action.equalsIgnoreCase(ACTION_ADD_ACCESS_TEAM)) {
	        	setHandled(request);
	        	actionForward = processActionAddAccessTeam(mapping, form, request, response, errors);
	        }
	        if (!isHandled(request) && action.equalsIgnoreCase(ACTION_ADD_BUYER)) {
	        	setHandled(request);
	        	actionForward = processActionAddBuyer(mapping, form, request, response, errors);
	        }

	        actionForward = super.handlePageEvent(mapping, formIn, request, response, errors);
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}

	protected ActionForward processOtherStatus(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response,
		ActionErrors errors, String rb_status) {

		HttpSession session = request.getSession(false);
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {
			if (rb_status.equalsIgnoreCase(STATUS_ADD_ATTACH)) {
				return processStatusAddAttach(mapping,  form,  request, response,  errors,  rb_status);
			} else if(rb_status.equalsIgnoreCase(STATUS_ADD_SIGNATURE_ATTACH)) {
				return processStatusAddSignatureAttach(mapping,  form,  request, response,  errors,  rb_status);
			} else if(rb_status.equalsIgnoreCase(STATUS_ADD_ACCESS_TEAM)) {
				return processStatusAddAccessTeam(mapping,  form,  request, response,  errors,  rb_status);
			}
			actionForward = super.processOtherStatus(mapping, formIn, request, response, errors, rb_status);
		} catch (Exception e) {
			Logger.log(this, e);
		}

		return actionForward;
	}

	public ActionForward processActionAddAccessTeam(ActionMapping mapping, ActionForm formIn, 
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
		ActionForward actionForward = new ActionForward(mapping.getInput());
		HttpSession session = request.getSession();
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		try {
			LinkedList criteriaList = new LinkedList();
			TableSchema[] childTs = form.getChildTs();
			TableSchema  ts = childTs[TAB_IDX_ACCESS_TEAM];
			String accessTeamCode = ts.getDisplayWebLabelByObjectId("LBL_ACCESS_TEAM_ACCESS_TEAM_CODE");
			String accessTeamName = ts.getDisplayWebLabelByObjectId("LBL_ACCESS_TEAM_ACCESS_TEAM_NAME");
			String accessTeamDescription = ts.getDisplayWebLabelByObjectId("LBL_ACCESS_TEAM_DESCRIPTION");
			criteriaList.add(accessTeamCode);
			criteriaList.add("INPUT_WITH_WILDCARD");
			criteriaList.add("");
			
			criteriaList.add(accessTeamName);
			criteriaList.add("INPUT_WITH_WILDCARD");
			criteriaList.add("");          

			ArrayList criteriaColumnList = new ArrayList();
			criteriaColumnList.add("ACCESS_TEAM_CODE");
			criteriaColumnList.add("ACCESS_TEAM_NAME");
			
			ArrayList rsltTextList = new ArrayList();
			ArrayList rsltColumnList = new ArrayList();
			Hashtable tblParams = new Hashtable();

			rsltTextList.add(accessTeamCode);
			rsltTextList.add(accessTeamName);
			rsltTextList.add(accessTeamDescription);
			    
			rsltColumnList.add("ACCESS_TEAM_CODE");            //Column 1
			rsltColumnList.add("ACCESS_TEAM_NAME");            //Column 2  
			rsltColumnList.add("DESCRIPTION");            //Column 3  
			
			String where = "COMPANY_CODE='" + WebUtil.getAppropriateCompanyCode(session, null)+"'";    
			                 			
			tblParams.put(ProjectConstants.SESSION_TABLE, "T_ACCESS_TEAM_HDR");
			tblParams.put(ProjectConstants.SESSION_WHERE, where);
			tblParams.put(ProjectConstants.SESSION_ORDERBY, "ACCESS_TEAM_CODE");
			
			HashMap params = new HashMap();
			params.put(ProjectConstants.SESSION_SESSION_NAME, getSessionSimpleMaintStatus());
			params.put(ProjectConstants.SESSION_SESSION_VALUE, STATUS_ADD_ACCESS_TEAM);
			params.put(ProjectConstants.SESSION_OPENER_PATH, getFunctionId());
			params.put(ProjectConstants.SESSION_EVENTSRC, form.getPageEventSrc());
			params.put(ProjectConstants.SESSION_CRITERIA_LIST, criteriaList);
			params.put(ProjectConstants.SESSION_CRITERIA_COLUMN_LIST, criteriaColumnList);
			params.put(ProjectConstants.SESSION_RESULT_TEXT_LIST, rsltTextList);
			params.put(ProjectConstants.SESSION_RESULT_COLUMN_LIST, rsltColumnList);
			params.put(ProjectConstants.SESSION_TABLE_PARAMS, tblParams);
			params.put(ProjectConstants.SESSION_AUTO_SEARCH, ProjectConstants.GENERIC_YES);
			session.setAttribute(ProjectConstants.SESSION_COMMON_SEARCH_PARAMETERS, params);
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
		
		return actionForward;
	}
	
	public ActionForward processStatusAddAccessTeam(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors, String rb_status) {
		ActionForward actionForward = new ActionForward(mapping.getInput());
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		HttpSession session = request.getSession();
		HashMap params = (HashMap) session.getAttribute(ProjectConstants.SESSION_COMMON_SEARCH_PARAMETERS);
        session.removeAttribute(ProjectConstants.SESSION_COMMON_SEARCH_PARAMETERS);
        session.removeAttribute(ProjectConstants.SESSION_ALEADY_EXISTS_ACCESS_TEAM);
        ArrayList selectedList = (ArrayList) params.get(ProjectConstants.SESSION_SELECTED_LIST);
        if (selectedList == null || selectedList.size() == 0)
            return actionForward; 
        try{
        	
        }
        catch (Exception e) {
            Logger.logExceptions(this, e);
        }
	    return actionForward;
	}

	
	public ActionForward processActionAddBuyer(ActionMapping mapping, ActionForm formIn, 
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
		ActionForward actionForward = new ActionForward(mapping.getInput());
		HttpSession session = request.getSession();
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		try {
			LinkedList criteriaList = new LinkedList();
			TableSchema[] childTs = form.getChildTs();
			TableSchema  ts = childTs[TAB_IDX_BUYER];
			String buyerCode = ts.getDisplayWebLabelByObjectId("LBL_BUYER_BUYER_CODE");
			String buyerName = ts.getDisplayWebLabelByObjectId("LBL_BUYER_BUYER_NAME");
			String buyerDescription = ts.getDisplayWebLabelByObjectId("LBL_BUYER_DESCRIPTION");
			criteriaList.add(buyerCode);
			criteriaList.add("INPUT_WITH_WILDCARD");
			criteriaList.add("");
			
			criteriaList.add(buyerName);
			criteriaList.add("INPUT_WITH_WILDCARD");
			criteriaList.add("");          

			ArrayList criteriaColumnList = new ArrayList();
			criteriaColumnList.add("CUST_CODE");
			criteriaColumnList.add("CUST_NAME");
			
			ArrayList rsltTextList = new ArrayList();
			ArrayList rsltColumnList = new ArrayList();
			Hashtable tblParams = new Hashtable();

			rsltTextList.add(buyerCode);
			rsltTextList.add(buyerName);
			rsltTextList.add(buyerDescription);
			    
			rsltColumnList.add("CUST_CODE");            //Column 1
			rsltColumnList.add("CUST_NAME");            //Column 2  
			rsltColumnList.add("REMARKS");            //Column 3  
			
			String where = "COMPANY_CODE='" + WebUtil.getAppropriateCompanyCode(session, null)+"'";    
			                 			
			tblParams.put(ProjectConstants.SESSION_TABLE, "T_CUST_HDR");
			tblParams.put(ProjectConstants.SESSION_WHERE, where);
			tblParams.put(ProjectConstants.SESSION_ORDERBY, "CUST_CODE");
			
			HashMap params = new HashMap();
			params.put(ProjectConstants.SESSION_SESSION_NAME, getSessionSimpleMaintStatus());
			params.put(ProjectConstants.SESSION_SESSION_VALUE, STATUS_ADD_BUYER);
			params.put(ProjectConstants.SESSION_OPENER_PATH, getFunctionId());
			params.put(ProjectConstants.SESSION_EVENTSRC, form.getPageEventSrc());
			params.put(ProjectConstants.SESSION_CRITERIA_LIST, criteriaList);
			params.put(ProjectConstants.SESSION_CRITERIA_COLUMN_LIST, criteriaColumnList);
			params.put(ProjectConstants.SESSION_RESULT_TEXT_LIST, rsltTextList);
			params.put(ProjectConstants.SESSION_RESULT_COLUMN_LIST, rsltColumnList);
			params.put(ProjectConstants.SESSION_TABLE_PARAMS, tblParams);
			params.put(ProjectConstants.SESSION_AUTO_SEARCH, ProjectConstants.GENERIC_YES);
			session.setAttribute(ProjectConstants.SESSION_COMMON_SEARCH_PARAMETERS, params);
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
		
		return actionForward;
	}

	private ActionForward processActionAddAttach(ActionMapping mapping, UserMaintenanceForm form,
            HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
        HttpSession session = request.getSession(false);
        ActionForward actionForward = new ActionForward(mapping.getInput());

        HashMap params = new HashMap();
        LinkedList keyList = new LinkedList();

        keyList.add("Company Code");
        keyList.add(form.getCompanyCode());

        String status = STATUS_ADD_ATTACH;

        params.put(ProjectConstants.SESSION_KEY_LIST, keyList);
        params.put(ProjectConstants.SESSION_UPLOAD_FILE_SESSION_NAME, getSessionSimpleMaintStatus());
        params.put(ProjectConstants.SESSION_UPLOAD_FILE_SESSION_VALUE, status);
        params.put(ProjectConstants.SESSION_OPENER_PATH, getFunctionId());
        session.setAttribute(ProjectConstants.SESSION_UPLOAD_FILE_PARAM, params);

        return actionForward;
    }

	private ActionForward processStatusAddAttach(ActionMapping mapping, UserMaintenanceForm form,
            HttpServletRequest request, HttpServletResponse response, ActionErrors errors, String rb_status) {
        ActionForward actionForward = new ActionForward(mapping.getInput());
        HttpSession session = request.getSession(false);
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {
            HashMap params = (HashMap) session.getAttribute(ProjectConstants.SESSION_UPLOAD_FILE_RETURN_PARAM);
            session.removeAttribute(ProjectConstants.SESSION_UPLOAD_FILE_RETURN_PARAM);

            if (params == null)
                return actionForward;

            FormFile file = (FormFile) params.get(ProjectConstants.SESSION_UPLOAD_FILE_RETURN_FORM_FILE);

            if (file == null)
                return actionForward;

            // retrieve the file name
            String fileName = file.getFileName();

            // retrieve the content type
            String contentType = file.getContentType();

            // retrieve the file data
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            InputStream stream = file.getInputStream();

            if (!CommonUtil.isEmpty(fileName)) {
//                if (!contentType.equalsIgnoreCase("image/bmp") && !contentType.equalsIgnoreCase("image/jpg")
//                        && !contentType.equalsIgnoreCase("image/gif")) {
//                    errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.image.contentType", "(bmp, jpg, gif)"));
//                    return actionForward;
//                }

                byte[] buffer = new byte[8192];
                int bytesRead = 0;
                while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
                    baos.write(buffer, 0, bytesRead);
                }

                form.setContentType(contentType);
                form.setSignature(baos.toByteArray());
            }
        } catch (Exception e) {
        	Logger.logExceptions(this, e);
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("exception.general", e.toString()));
        }
        return actionForward;
    }

    private ActionForward processActionViewAttach(ActionMapping mapping, UserMaintenanceForm form,
            HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
        HttpSession session = request.getSession(false);
        ActionForward actionForward = null;

        try {
            OutputStream out = response.getOutputStream();
            response.setContentType(form.getContentType());
            response.setStatus(HttpServletResponse.SC_OK);
            byte[] content = form.getSignature();
            out.write(content);
            out.close();
        } catch (Exception e) {
        	Logger.logExceptions(this, e);
        }

        return actionForward;
    }
    
    private ActionForward processActionDelAttach(ActionMapping mapping, UserMaintenanceForm form,
            HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
        ActionForward actionForward = new ActionForward(mapping.getInput());

        form.setContentType("");
        form.setSignature(null);

        return actionForward;
    }

    
	private ActionForward processActionAddSignatureAttach(ActionMapping mapping, UserMaintenanceForm form,
            HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
        HttpSession session = request.getSession(false);
        ActionForward actionForward = new ActionForward(mapping.getInput());

        HashMap params = new HashMap();
        LinkedList keyList = new LinkedList();

        keyList.add("Company Code");
       keyList.add(form.getCompanyCode());

        String status = STATUS_ADD_SIGNATURE_ATTACH;

        params.put(ProjectConstants.SESSION_KEY_LIST, keyList);
        params.put(ProjectConstants.SESSION_UPLOAD_FILE_SESSION_NAME, getSessionSimpleMaintStatus());
        params.put(ProjectConstants.SESSION_UPLOAD_FILE_SESSION_VALUE, status);
        params.put(ProjectConstants.SESSION_OPENER_PATH, getFunctionId());
        session.setAttribute(ProjectConstants.SESSION_UPLOAD_FILE_PARAM, params);

        return actionForward;


    }

    private ActionForward processStatusAddSignatureAttach(ActionMapping mapping, UserMaintenanceForm form,
            HttpServletRequest request, HttpServletResponse response, ActionErrors errors, String rb_status) {
        ActionForward actionForward = new ActionForward(mapping.getInput());
        HttpSession session = request.getSession(false);
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {
            HashMap params = (HashMap) session.getAttribute(ProjectConstants.SESSION_UPLOAD_FILE_RETURN_PARAM);
            session.removeAttribute(ProjectConstants.SESSION_UPLOAD_FILE_RETURN_PARAM);

            if (params == null)
                return actionForward;

            FormFile file = (FormFile) params.get(ProjectConstants.SESSION_UPLOAD_FILE_RETURN_FORM_FILE);

            if (file == null)
                return actionForward;

            // retrieve the file name
            String fileName = file.getFileName();

            // retrieve the content type
            String contentType = file.getContentType();

            // retrieve the file data
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            InputStream stream = file.getInputStream();
 
            String eventSrc = form.getPageEventSrc(); // for display key fields
            int idx = Integer.parseInt(eventSrc);
            ArrayList rows = form.getMultiRows(TAB_IDX_SIGNATURE);

        } catch (Exception e) {
        	Logger.logExceptions(this, e);
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("exception.general", e.toString()));
        }
        return actionForward;
    }
    
    private ActionForward processActionViewSignatureAttach(ActionMapping mapping, UserMaintenanceForm form,
            HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
        HttpSession session = request.getSession(false);
        ActionForward actionForward = null;

        try {} catch (Exception e) {
        	Logger.logExceptions(this, e);
        }

        return actionForward;
    }
    



    

   
	////////////////////////////////////////////////////////////////////////////////
	// END OF LOGICAL AND BUSINESS METHODS
	////////////////////////////////////////////////////////////////////////////////


	////////////////////////////////////////////////////////////////////////////////
	// OVERRIDES PARENT'S OPTIONAL METHODS
	////////////////////////////////////////////////////////////////////////////////

	protected void initAction(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		super.initAction(mapping, formIn, request, response, errors);

		HttpSession session = request.getSession(false);
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {
//			HashMap errMsgMap = WebUtil.getModuleErrorMessages(editingUser.getCompanyCode(),
//				DBMENU_GENERAL_MENU, form.getModuleName(), form.getSysLangCode(), DBMENU_OBJECT_TYPE_ERR_MSG);
//			form.setErrMsgMap(errMsgMap);

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void initForm(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		super.initForm(mapping, formIn, request, response, errors);

		HttpSession session = request.getSession(false);
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void initPage(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		super.initPage(mapping, formIn, request, response, errors);

		HttpSession session = request.getSession(false);
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void beforeCreate(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {
			form.setCompanyCode(WebUtil.getAppropriateCompanyCode(session, ProjectConstants.SP_SHARE_USER_SETUP));
			form.setTs(new UserSchema());
			form.setTsName("com.erp.app.admin.userSetup.schema.UserSchema");
			form.setActivation(ProjectConstants.GENERIC_ACTIVE);
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void beforeSave(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void afterSave(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void beforeEdit(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void afterEdit(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void beforeDelete(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void afterDelete(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void beforeRefresh(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void afterRefresh(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	public String getSessionMaintStatus() {

		return getSessionSimpleMaintStatus();
	}

	public String getSessionMaintPk() {

		return getSessionSimpleMaintPk();
	}

	public String getStrutsId() {

		return getFunctionId();
	}

	public String getSimpleFormReadOnlySessionName(){

		return ProjectConstants.SESSION_USER_FORM_READ_ONLY_SESSION_NAME;
	}

	public String getSimpleFormReadOnlyCallerSessionName(){

		return ProjectConstants.SESSION_USER_FORM_READ_ONLY_CALLER_SESSION_NAME;
	}

	protected String getSimpleSrchMenuId() {

		return ProjectConstants.MOD_USER_SETUP;
	}

	////////////////////////////////////////////////////////////////////////////////
	// END OF OPTIONAL METHODS
	////////////////////////////////////////////////////////////////////////////////


	////////////////////////////////////////////////////////////////////////////////
	// IMPLEMENTS PARENT'S ABSTRACT METHODS
	////////////////////////////////////////////////////////////////////////////////

	protected String getModuleName(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request,HttpServletResponse response) {

		return ProjectConstants.MOD_USER_SETUP;
	}

	protected String getFunctionId() {

		//struts-config xxxxx.do
		return "userMaintenance.do";
	}

	protected Class getMasterFormClass() {

		//the corresponding form class
		return UserMaintenanceForm.class;
	}

	protected Class getMasterVOClass() {

		//corresponding master vo class
		return UserVo.class;
	}

	protected String getMasterFormSessionName() {

		return "userMaintenanceForm";
	}

//	protected Class[] getChildRowClass() {
//
//		Class[] childRowClass = new Class[0];
//
//
//		return childRowClass;
//	}
//
//	protected String[] getFolderChildIdxMapping() {
//
//		String[] folderChildIdx = new String[1];
//
//
//		return folderChildIdx;
//	}

	protected Class[] getChildRowClass() {

		Class[] childRowClass = new Class[6];



		return childRowClass;
	}

	protected String[] getFolderChildIdxMapping() {

		String[] folderChildIdx = new String[7];

		folderChildIdx[0] = String.valueOf(TAB_IDX_GMM);

		
		return folderChildIdx;
	}
	
	protected SimpleBasePk getPk(ActionForm formIn, HttpServletRequest request) {

		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		UserPk pk = null;
		HttpSession session = request.getSession(false);

		String companyCode = WebUtil.getAppropriateCompanyCode(session, ProjectConstants.SP_SHARE_USER_SETUP);

		pk = new UserPk(form.getUserCode(), companyCode);
		return pk;
	}

	protected void setFormType(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
		HttpServletResponse response, ActionErrors errors){

		UserMaintenanceForm form = (UserMaintenanceForm) formIn;
		form.setFormType(ProjectConstants.FORM_TYPE_MAINT);
	}

	protected void afterExecuteAction(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response) {
        ((UserMaintenanceForm)formIn).setCompanyCode(WebUtil.getAppropriateCompanyCode(request.getSession(false),ProjectConstants.SP_SHARE_USER_SETUP ));
 }
	
	////////////////////////////////////////////////////////////////////////////////
	// END OF ABSTRACT METHODS
	////////////////////////////////////////////////////////////////////////////////
}
